var util = require('util');
/**
 * 
 * @fileOverview View control for the edit port page.
 * @author jmanero
 * 
 */

/** @ignore */
exports.callback = function(req, res, next) {
	try {
	model.Port.findOne({
		_id : req.params.port
	}, function(e) {
		model.Message.error(e);
	}).populate('device').run(function(e, port) {
		model.Message.error(e);
		if (!port) {
			res.redirect('https://' + req.header('X-Request-Host') + '/ports/');
//				res.render('editPort.jade', {
//					pageTitle : 'Port Configuration',
//					port : new model.Port(),
//					device : device,
//					action : 'add',
//					pretty : true
//				});
		} else {
			res.render('editPort.jade', {
				pageTitle : 'Port Configuration',
				port : port,
				action : 'update',
				pretty : true
			});
		}
	});
	} catch(e) {
		model.Message.error(e);
		res.render('error.jade', {
			pageTitle : 'Error',
			e : e,
			date : Date.now()
		});
	}
};

/** @ignore */
exports.path = '/ports/:port';

/** @ignore */
exports.method = 'get';
